/*
 * @Author: dongweipeng dongweipeng@supos.com
 * @Date: 2024-12-30 08:52:17
 * @LastEditors: dongweipeng dongweipeng@supos.com
 * @LastEditTime: 2025-01-17 13:51:20
 * @FilePath: \supos-ce-fuxa\client\src\utils\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export const queryLocationParam = (location: any, param: string) => {
    const paramArray = location.search.substr(1).split('&');
    let result = '';

    paramArray.forEach((item) => {
        const [key, value] = item.split('=');
        if (key === param) {
            result = value;
        }
    });

    return result;
};

export const checkEditor = () => {
    const isEditor = window.location.pathname.includes('/editor') || window.location.search.includes('status=editor');
    return isEditor;
};

export const navigate = (router, goto, params?: any) => {
    const projectrId = queryLocationParam(window.location, 'id');
    const viewId = queryLocationParam(window.location, 'viewId');
    router.navigate(Array.isArray(goto) ? goto : [goto], { queryParams: { ...(params || {}), id: projectrId, viewId } });
};
